package com.isoft;


import com.isoft.data.service.AllService;
import com.isoft.data.service.AllService2;
import com.isoft.data.util.ParseXmlUtil;
import com.isoft.data.xml.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.File;
import java.io.IOException;

@SpringBootTest
public class ParseXmlApplicationTests3 {
    @Value("${xml.path}")
    String path;

    @Autowired
    AllService2 allService2;
    @Test
    void contextLoads() throws IOException{
//        DFME_FETT dfme_fett= ParseXmlUtil.parseFromFile(path,"DFME-FETT-20170608204824.xml", DFME_FETT.class);
//        System.out.println(allService.addFETT(dfme_fett));

        String folderPath = "E:\\六周实训\\2017六月上旬消息";
//        String filenamePrefix = "DFME-DEPE";
//        String filenamePrefix = "DFME-DLYE";
//        String filenamePrefix = "DFME-FETT";
//        String filenamePrefix="DFME-FPTT";
//        String filenamePrefix="DFME-FRTT";

        String filenamePrefix="DFME-GTLS";

//        String filenamePrefix="BASE-CFIE";
//        String filenamePrefix="DFOE-DFDE";
        File folder = new File(folderPath);
        searchFiles(folder,filenamePrefix);
    }

    public void searchFiles(File folder, String filenamePrefix) throws IOException {
        if (folder.isDirectory()) {
            File[] files = folder.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.isFile() && file.getName().startsWith(filenamePrefix)) {
                        System.out.println(file.getName());
//                        DFME_DLYE  DFME_DLYE =
//                                ParseXmlUtil.parseFromFile(folder.getPath(), file.getName(),  DFME_DLYE.class);
//                        System.out.println(allService2.addDLYE(DFME_DLYE));

//                        DFME_DEPE DFME_DEPE =
//                                ParseXmlUtil.parseFromFile(folder.getPath(), file.getName(),  DFME_DEPE.class);
//                        System.out.println(allService2.addDEPE(DFME_DEPE));

//                        DFME_FETT DFME_FETT =
//                                ParseXmlUtil.parseFromFile(folder.getPath(), file.getName(),  DFME_FETT.class);
//                        System.out.println(allService2.addFETT(DFME_FETT));

//                        Fptt fptt=
//                                ParseXmlUtil.parseFromFile(folder.getPath(), file.getName(),  Fptt.class);
//                        System.out.println(allService2.addFptt(fptt));

//                        Frtt frtt=
//                                ParseXmlUtil.parseFromFile(folder.getPath(), file.getName(),  Frtt.class);
//                        System.out.println(allService2.addFrtt(frtt));

                        Gtls gtls=
                                ParseXmlUtil.parseFromFile(folder.getPath(), file.getName(), Gtls.class);
                        System.out.println(allService2.addGtls(gtls));



//                        Cfie cfie =
//                                ParseXmlUtil.parseFromFile(folder.getPath(), file.getName(), Cfie.class);
//                        System.out.println(allService2.addCfie(cfie));

//                        Dfde dfde =
//                                ParseXmlUtil.parseFromFile(folder.getPath(), file.getName(), Dfde.class);
//                        System.out.println(allService2.addDfde(dfde));
                    } else if (file.isDirectory()) {
                        searchFiles(file, filenamePrefix); // 递归调用，检索子文件夹
                    }
                }
            }
        }
    }
}
